package logic

import (
	"context"
	"gorm.io/gorm"
	"house/models/mysql"

	"house/houserpc/houserpc"
	"house/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListLogic) HouseList(in *houserpc.HouseListRequest) (*houserpc.HouseListResponse, error) {
	// todo: add your logic here and delete this line

	var house mysql.House
	mysql.DB.Debug().Where("title", in.HouseId).Find(&house)

	houses := mysql.House{
		Model: gorm.Model{ID: house.ID},
	}
	mysql.DB.Debug().Find(&houses)

	return &houserpc.HouseListResponse{
		Title:   houses.Title,
		Price:   float32(houses.Price),
		Address: houses.Address,
	}, nil
}
